-- ====================================
-- Initialize the Graphical User Interface
-- ====================================
Orunj.icons = {}
local UIParent = _G.UIParent
local textureLookup = {
	debug = [[Interface\AddOns\Orunj\Art\OrunjIcon.tga]]
}

-- WorldMapFrame test
OrunjPoint = {
	
	-- Update the draw position
	Update = function(self)
		local x,y = GetPlayerMapPosition(self.player.unitId)
		-- local x, y = 0, 0,
		self.frame:ClearAllPoints()
		-- TODO: Need to scale the X and Y positions accordingly.
		self.frame:SetPoint("CENTER", self.frame:GetParent(), "CENTER", x*100, -y*100)		
		--[[ 
		if needUpdate then
			self.frame:ClearAllPoints()
			self.frame:SetPoint("CENTER", self.frame:GetParent(), "CENTER", x, y)
		end
		]]--
		
		if Orunj.recording then
			self.frame:Show()
		else
			self.frame:Hide()
		end
	end,
	
	-- Set the texture of the point
	SetTexture = function(self, texfile)
		local tex = self.texture
		tex:SetTexture(texfile)		
		tex:SetBlendMode("BLEND")
		return self
	end,
	
	-- Returns a new OrunjPoint attached to the specific frame.
	New = function(self, orunjPlayer, texfile, frame)
		local t = {}
		-- Allow us to access the OrunjPoint functions using the
		-- current t table.
		t = setmetatable({}, {__index = self})
		
		-- Set the player to follow along the map.
		t.player = orunjPlayer 
		
		-- Make the frame.
		-- t.frame = CreateFrame("Frame", "pants", frame)
		t.frame = CreateFrame("Frame", nil, frame)
		t.frame:SetFrameStrata("HIGH")
		t.frame:SetWidth(64)
		t.frame:SetHeight(64)
		
		-- Make the texture.
		t.texture = t.frame:CreateTexture()
		t.texture:SetAllPoints()
		t.texfile = texfile
		t:SetTexture(texfile)
		
		return t
	end,
}

function Orunj:InitializeIcons()
	-- TODO: Initialize one icon for each player.
	self.icons = {}
	for k, v in pairs(self.session.players) do
		self.icons[k] = OrunjPoint:New(self.session.players[k], textureLookup.debug, WorldMapFrame)
	end
end

function Orunj:UpdateIcons()
	-- TODO: Update the icons every timestep.
	for k, v in pairs(self.icons) do
		v:Update()
	end
end
--[[
Orunj.canvas = CreateFrame("Frame", "OrunjCanvas", UIParent)
Orunj.canvas:SetSize(UIParent:GetWidth(), UIParent:GetHeight())
Orunj.canvas:SetPoint("CENTER")
]]--